#include "databasehelper.h"
#include <QDebug>
#include <QSqlError>
#include <QSqlQuery>
#include <QApplication>
DatabaseHelper::DatabaseHelper()
{
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("env.db");
    if(!db.open())
    {
        qDebug()<<"database open error: " + db.lastError().text();
    }
}

bool DatabaseHelper::isExist(QString name, QString passwd)
{
    QSqlQuery query(db);
    query.prepare("select * from env_user where name = :uname and password = :upwd");
    query.bindValue(":uname",name);
    query.bindValue(":upwd",passwd);
    if(!query.exec())
    {
        qDebug()<<"查询出错..."+query.lastError().text();
        return false;
    }
    if(!query.next())
    {
        qDebug()<<"未查询到["+name+"]的信息";
        return false;
    }
    else
    {
        qDebug()<<"["+name+"]登录成功！";
        return true;
    }
}

DatabaseHelper::~DatabaseHelper()
{
    qDebug()<<"db has disponsed";
}
